package com.xintoucloud.pbs.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xintoucloud.pbs.entity.OrganizationStage;
import com.xintoucloud.pbs.model.OrganizationStageDto;
import com.xintoucloud.pbs.service.OrganizationStageService;
@Controller@RequestMapping("/organizationStage")
public class OrganizationStageController {
	@Autowired
	private OrganizationStageService organizationStageService;
	
	@RequestMapping("/stage")
	public String get() {
		return "organization_stage";
	}
	
	@GetMapping("/list")
	@ResponseBody
	public Map<String,Object> list(){
		List<OrganizationStageDto> list = organizationStageService.list();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("code",0);
		map.put("data", list);
		return map;
	}
	@RequestMapping("/delete")
	public String delete(HttpServletRequest request) {
		String id = request.getParameter("id");
		System.out.println("+++++++++++++++++++"+id);
		organizationStageService.delete(Integer.parseInt(id));
		return "redirect:organization_stage";
	}
	
	@PostMapping("/update")
	public String update(HttpServletRequest request) {
		String osgid = request.getParameter("osgid");
		String ostage = request.getParameter("ostage");
		String detail = request.getParameter("detail");
		OrganizationStage organizationStage = new OrganizationStage();
		organizationStage.setOsgid(Integer.parseInt(osgid));
		organizationStage.setOstage(ostage);
		organizationStage.setDetail(detail);
		organizationStageService.update(organizationStage);
		return "redirect:stage";
	}
}
